package com.sugon.controller.device;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.DevSpecialWorstationEntity;
import com.sugon.service.DevSpecialWorstationService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

import static com.sugon.utils.ShiroUtils.getUserId;

/**
 * 特殊设备工位关联Controller
 *
 * @author sugon
 * @date 2019-07-26 15:31:17
 */
@Controller
@RequestMapping("devspecialworstation")
public class DevSpecialWorstationController {
    @Autowired
    private DevSpecialWorstationService devSpecialWorstationService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
//    @RequiresPermissions("devspecialworstation:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<DevSpecialWorstationEntity> devSpecialWorstationList = devSpecialWorstationService.queryList(query);
        int total = devSpecialWorstationService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(devSpecialWorstationList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
//    @RequiresPermissions("devspecialworstation:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        DevSpecialWorstationEntity devSpecialWorstation = devSpecialWorstationService.queryObject(id);

        return R.ok().put("devSpecialWorstation", devSpecialWorstation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("devspecialworstation:save")
    @ResponseBody
    public R save(@RequestBody DevSpecialWorstationEntity devSpecialWorstation) {
        devSpecialWorstation.setCreateUser(getUserId());
        devSpecialWorstation.setCreateTime(new Date());
        devSpecialWorstationService.save(devSpecialWorstation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("devspecialworstation:update")
    @ResponseBody
    public R update(@RequestBody DevSpecialWorstationEntity devSpecialWorstation) {
        devSpecialWorstation.setUpdateUser(getUserId());
        devSpecialWorstation.setUpdateTime(new Date());
        devSpecialWorstationService.update(devSpecialWorstation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("devspecialworstation:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        devSpecialWorstationService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<DevSpecialWorstationEntity> list = devSpecialWorstationService.queryList(params);

        return R.ok().put("list", list);
    }
}
